using System;
using System.Collections.Generic;
using System.Text;
using Entity;
using ECommerce.Library.DataStructure;

namespace AutoGear.BLL
{
    public class ProductStock
    {
        int _stockId;
        string _size = string.Empty;
        double _weight;
        string _weightUnit = string.Empty;
        int _widthWholeNumberFirstDigit;
        int _widthWholeNumberSecondDigit;
        int _widthFractionNumberFirstDigit;
        int _widthFractionNumberSecondDigit;
        double _widthValue;
        string _widthUnit = string.Empty;
        int _diameterWholeNumberFirstDigit;
        int _diameterWholeNumberSecondDigit;
        int _diameterFractionNumberFirstDigit;
        int _diameterFractionNumberSecondDigit;
        double _diameterValue;
        string _diameterUnit = string.Empty;
        int _threadCountWholeNumberFirstDigit;
        int _threadCountWholeNumberSecondDigit;
        int _threadCountFractionNumberFirstDigit;
        int _threadCountFractionNumberSecondDigit;
        double _threadCountValue;
        string _threadCountUnit = string.Empty;
        int _lengthWholeNumberFirstDigit;
        int _lengthWholeNumberSecondDigit;
        int _lengthFractionNumberFirstDigit;
        int _lengthFractionNumberSecondDigit;
        double _lengthValue;
        string _lengthUnit = string.Empty;
        int _stockAmount;
        int _productId;
        int _pkgQuanity;
        bool _useDecimalForSize;

        public int StockId
        {
            get { return _stockId; }
            private set { _stockId = value; }
        }

        public string Size
        {
            get { return _size; }
            set { _size = value; }
        }

        public double Weight
        {
            get { return _weight; }
            set { _weight = value; }
        }

        public string WeightUnit
        {
            get { return _weightUnit; }
            set { _weightUnit = value; }
        }

        public int WidthWholeNumberFirstDigit
        {
            get { return _widthWholeNumberFirstDigit; }
            set { _widthWholeNumberFirstDigit = value; }
        }

        public int WidthWholeNumberSecondDigit
        {
            get { return _widthWholeNumberSecondDigit; }
            set { _widthWholeNumberSecondDigit = value; }
        }

        public int WidthFractionNumberFirstDigit
        {
            get { return _widthFractionNumberFirstDigit; }
            set { _widthFractionNumberFirstDigit = value; }
        }

        public int WidthFractionNumberSecondDigit
        {
            get { return _widthFractionNumberSecondDigit; }
            set { _widthFractionNumberSecondDigit = value; }
        }

        public double WidthValue
        {
            get { return _widthValue; }
            set { _widthValue = value; }
        }

        public string WidthUnit
        {
            get { return _widthUnit; }
            set { _widthUnit = value; }
        }

        public int DiameterWholeNumberFirstDigit
        {
            get { return _diameterWholeNumberFirstDigit; }
            set { _diameterWholeNumberFirstDigit = value; }
        }

        public int DiameterWholeNumberSecondDigit
        {
            get { return _diameterWholeNumberSecondDigit; }
            set { _diameterWholeNumberSecondDigit = value; }
        }

        public int DiameterFractionNumberFirstDigit
        {
            get { return _diameterFractionNumberFirstDigit; }
            set { _diameterFractionNumberFirstDigit = value; }
        }

        public int DiameterFractionNumberSecondDigit
        {
            get { return _diameterFractionNumberSecondDigit; }
            set { _diameterFractionNumberSecondDigit = value; }
        }

        public double DiameterValue
        {
            get { return _diameterValue; }
            set { _diameterValue = value; }
        }

        public string DiameterUnit
        {
            get { return _diameterUnit; }
            set { _diameterUnit = value; }
        }

        public int ThreadCountWholeNumberFirstDigit
        {
            get { return _threadCountWholeNumberFirstDigit; }
            set { _threadCountWholeNumberFirstDigit = value; }
        }

        public int ThreadCountWholeNumberSecondDigit
        {
            get { return _threadCountWholeNumberSecondDigit; }
            set { _threadCountWholeNumberSecondDigit = value; }
        }

        public int ThreadCountFractionNumberFirstDigit
        {
            get { return _threadCountFractionNumberFirstDigit; }
            set { _threadCountFractionNumberFirstDigit = value; }
        }

        public int ThreadCountFractionNumberSecondDigit
        {
            get { return _threadCountFractionNumberSecondDigit; }
            set { _threadCountFractionNumberSecondDigit = value; }
        }

        public double ThreadCountValue
        {
            get { return _threadCountValue; }
            set { _threadCountValue = value; }
        }

        public string ThreadCountUnit
        {
            get { return _threadCountUnit; }
            set { _threadCountUnit = value; }
        }

        public int LengthWholeNumberFirstDigit
        {
            get { return _lengthWholeNumberFirstDigit; }
            set { _lengthWholeNumberFirstDigit = value; }
        }

        public int LengthWholeNumberSecondDigit
        {
            get { return _lengthWholeNumberSecondDigit; }
            set { _lengthWholeNumberSecondDigit = value; }
        }

        public int LengthFractionNumberFirstDigit
        {
            get { return _lengthFractionNumberFirstDigit; }
            set { _lengthFractionNumberFirstDigit = value; }
        }

        public int LengthFractionNumberSecondDigit
        {
            get { return _lengthFractionNumberSecondDigit; }
            set { _lengthFractionNumberSecondDigit = value; }
        }

        public double LengthValue
        {
            get { return _lengthValue; }
            set { _lengthValue = value; }
        }

        public string LengthUnit
        {
            get { return _lengthUnit; }
            set { _lengthUnit = value; }
        }

        public int StockAmount
        {
            get { return _stockAmount; }
            set { _stockAmount = value; }
        }

        public int ProductId
        {
            get { return _productId; }
            set { _productId = value; }
        }

        public int PkgQuanity
        {
            get { return _pkgQuanity; }
            set { _pkgQuanity = value; }
        }

        public bool UseDecimalForSize
        {
            get { return _useDecimalForSize; }
            set { _useDecimalForSize = value; }
        }

        public ProductStock() { 
        }

        public ProductStock(
            int stockId,
            string size,
            double weight,
            string weightUnit,
            int widthWholeNumberFirstDigit,
            int widthWholeNumberSecondDigit,
            int widthFractionNumberFirstDigit,
            int widthFractionNumberSecondDigit,
            double widthValue,
            string widthUnit,
            int diameterWholeNumberFirstDigit,
            int diameterWholeNumberSecondDigit,
            int diameterFractionNumberFirstDigit,
            int diameterFractionNumberSecondDigit,
            double diameterValue,
            string diameterUnit,
            int threadCountWholeNumberFirstDigit,
            int threadCountWholeNumberSecondDigit,
            int threadCountFractionNumberFirstDigit,
            int threadCountFractionNumberSecondDigit,
            double threadCountValue,
            string threadCountUnit,
            int lengthWholeNumberFirstDigit,
            int lengthWholeNumberSecondDigit,
            int lengthFractionNumberFirstDigit,
            int lengthFractionNumberSecondDigit,
            double lengthValue,
            string lengthUnit,
            int stockAmount,
            int productId,
            int pkgQuanity,
            bool useDecimalForSize
            )
        {
            this._stockId = stockId;
            this._size = size;
            this._weight = weight;
            this._weightUnit = weightUnit;
            this._widthWholeNumberFirstDigit = widthWholeNumberFirstDigit;
            this._widthWholeNumberSecondDigit = widthWholeNumberSecondDigit;
            this._widthFractionNumberFirstDigit = widthFractionNumberFirstDigit;
            this._widthFractionNumberSecondDigit = widthFractionNumberSecondDigit;
            this._widthValue = widthValue;
            this._widthUnit = widthUnit;
            this._diameterWholeNumberFirstDigit = diameterWholeNumberFirstDigit;
            this._diameterWholeNumberSecondDigit = diameterWholeNumberSecondDigit;
            this._diameterFractionNumberFirstDigit = diameterFractionNumberFirstDigit;
            this._diameterFractionNumberSecondDigit = diameterFractionNumberSecondDigit;
            this._diameterValue = diameterValue;
            this._diameterUnit = diameterUnit;
            this._threadCountWholeNumberFirstDigit = threadCountWholeNumberFirstDigit;
            this._threadCountWholeNumberSecondDigit = threadCountWholeNumberSecondDigit;
            this._threadCountFractionNumberFirstDigit = threadCountFractionNumberFirstDigit;
            this._threadCountFractionNumberSecondDigit = threadCountFractionNumberSecondDigit;
            this._threadCountValue = threadCountValue;
            this._threadCountUnit = threadCountUnit;
            this._lengthWholeNumberFirstDigit = lengthWholeNumberFirstDigit;
            this._lengthWholeNumberSecondDigit = lengthWholeNumberSecondDigit;
            this._lengthFractionNumberFirstDigit = lengthFractionNumberFirstDigit;
            this._lengthFractionNumberSecondDigit = lengthFractionNumberSecondDigit;
            this._lengthValue = lengthValue;
            this._lengthUnit = lengthUnit;
            this._stockAmount = stockAmount;
            this._productId = productId;
            this._pkgQuanity = pkgQuanity;
            this._useDecimalForSize = useDecimalForSize;
        }

        public ProductStock(TblProductStock stockData)
        {
            this._stockId = stockData.StockId;
            this._size = stockData.Size;
            this._weight = Convert.ToDouble( stockData.Weight);
            this._weightUnit = stockData.WeightUnit;
            this._widthWholeNumberFirstDigit = stockData.WidthWholeNumberFirstDigit;
            this._widthWholeNumberSecondDigit = stockData.WidthWholeNumberSecondDigit;
            this._widthFractionNumberFirstDigit = stockData.WidthFractionNumberFirstDigit;
            this._widthFractionNumberSecondDigit = stockData.WidthFractionNumberSecondDigit;
            this._widthValue = Convert.ToDouble( stockData.WidthValue);
            this._widthUnit = stockData.WidthUnit;
            this._diameterWholeNumberFirstDigit = stockData.DiameterWholeNumberFirstDigit;
            this._diameterWholeNumberSecondDigit = stockData.DiameterWholeNumberSecondDigit;
            this._diameterFractionNumberFirstDigit = stockData.DiameterFractionNumberFirstDigit;
            this._diameterFractionNumberSecondDigit = stockData.DiameterFractionNumberSecondDigit;
            this._diameterValue = Convert.ToDouble( stockData.DiameterValue);
            this._diameterUnit = stockData.DiameterUnit;
            this._threadCountWholeNumberFirstDigit = stockData.ThreadCountWholeNumberFirstDigit;
            this._threadCountWholeNumberSecondDigit = stockData.ThreadCountWholeNumberSecondDigit;
            this._threadCountFractionNumberFirstDigit = stockData.ThreadCountFractionNumberFirstDigit;
            this._threadCountFractionNumberSecondDigit = stockData.ThreadCountFractionNumberSecondDigit;
            this._threadCountValue =Convert.ToDouble(  stockData.ThreadCountValue);
            this._threadCountUnit = stockData.ThreadCountUnit;
            this._lengthWholeNumberFirstDigit = stockData.LengthWholeNumberFirstDigit;
            this._lengthWholeNumberSecondDigit = stockData.LengthWholeNumberSecondDigit;
            this._lengthFractionNumberFirstDigit = stockData.LengthFractionNumberFirstDigit;
            this._lengthFractionNumberSecondDigit = stockData.LengthFractionNumberSecondDigit;
            this._lengthValue = Convert.ToDouble(stockData.LengthValue);
            this._lengthUnit = stockData.LengthUnit;
            this._stockAmount = stockData.StockAmount;
            this._productId = stockData.ProductId;
            this._pkgQuanity = stockData.PkgQuanity;
            this._useDecimalForSize = stockData.UseDecimalForSize;
        }

        public static ReadWriteCustomCollection<ProductStock> LoadFromCustomCollection(ECommerce.DAL.CustomCollection<TblProductStock> stockData)
        {
            ReadWriteCustomCollection<ProductStock> result = new ReadWriteCustomCollection<ProductStock>();

            for (int i = 0; i < stockData.Count; i++)
            {
                result.Add(new ProductStock(stockData[i]));
            }

            return result;
        }

        public static void Create(ProductStock stock)
        {
//          int stockId = TblProductStock.CreateNewTblProductStock(stock.Size,Convert.Todouble(stock.Weight), string.Empty, stock.StockAmount, stock.ProductId, stock.PkgQuanity);
            TblProductStock tblProductStock = new TblProductStock();
            tblProductStock.Size = stock.Size;
            tblProductStock.Weight = Convert.ToDecimal(stock.Weight);
            tblProductStock.WeightUnit = stock.WeightUnit;
            tblProductStock.WidthWholeNumberFirstDigit = stock.WidthWholeNumberFirstDigit;
            tblProductStock.WidthWholeNumberSecondDigit = stock.WidthWholeNumberSecondDigit;
            tblProductStock.WidthFractionNumberFirstDigit = stock.WidthFractionNumberFirstDigit;
            tblProductStock.WidthFractionNumberSecondDigit = stock.WidthFractionNumberSecondDigit;
            tblProductStock.WidthValue =Convert.ToDecimal( stock.WidthValue);
            tblProductStock.WidthUnit = stock.WidthUnit;
            tblProductStock.DiameterWholeNumberFirstDigit = stock.DiameterWholeNumberFirstDigit;
            tblProductStock.DiameterWholeNumberSecondDigit = stock.DiameterWholeNumberSecondDigit;
            tblProductStock.DiameterFractionNumberFirstDigit = stock.DiameterFractionNumberFirstDigit;
            tblProductStock.DiameterFractionNumberSecondDigit = stock.DiameterFractionNumberSecondDigit;
            tblProductStock.DiameterValue =Convert.ToDecimal( stock.DiameterValue);
            tblProductStock.DiameterUnit = stock.DiameterUnit;
            tblProductStock.ThreadCountWholeNumberFirstDigit = stock.ThreadCountWholeNumberFirstDigit;
            tblProductStock.ThreadCountWholeNumberSecondDigit = stock.ThreadCountWholeNumberSecondDigit;
            tblProductStock.ThreadCountFractionNumberFirstDigit = stock.ThreadCountFractionNumberFirstDigit;
            tblProductStock.ThreadCountFractionNumberSecondDigit = stock.ThreadCountFractionNumberSecondDigit;
            tblProductStock.ThreadCountValue =Convert.ToDecimal( stock.ThreadCountValue);
            tblProductStock.ThreadCountUnit = stock.ThreadCountUnit;
            tblProductStock.LengthWholeNumberFirstDigit = stock.LengthWholeNumberFirstDigit;
            tblProductStock.LengthWholeNumberSecondDigit = stock.LengthWholeNumberSecondDigit;
            tblProductStock.LengthFractionNumberFirstDigit = stock.LengthFractionNumberFirstDigit;
            tblProductStock.LengthFractionNumberSecondDigit = stock.LengthFractionNumberSecondDigit;
            tblProductStock.LengthValue = Convert.ToDecimal(stock.LengthValue);
            tblProductStock.LengthUnit = stock.LengthUnit;
            tblProductStock.StockAmount = stock.StockAmount;
            tblProductStock.ProductId = stock.ProductId;
            tblProductStock.PkgQuanity = stock.PkgQuanity;
            tblProductStock.UseDecimalForSize = stock.UseDecimalForSize;
            tblProductStock.Save();
        }

        public void Update()
        {
            TblProductStock tblProductStock = TblProductStock.GetTblProductStockByStockId(this.StockId);
            tblProductStock.Size = this.Size;
            tblProductStock.Weight = Convert.ToDecimal(this.Weight);
            tblProductStock.WeightUnit = this.WeightUnit;
            tblProductStock.WidthWholeNumberFirstDigit = this.WidthWholeNumberFirstDigit;
            tblProductStock.WidthWholeNumberSecondDigit = this.WidthWholeNumberSecondDigit;
            tblProductStock.WidthFractionNumberFirstDigit = this.WidthFractionNumberFirstDigit;
            tblProductStock.WidthFractionNumberSecondDigit = this.WidthFractionNumberSecondDigit;
            tblProductStock.WidthValue = Convert.ToDecimal(this.WidthValue);
            tblProductStock.WidthUnit = this.WidthUnit;
            tblProductStock.DiameterWholeNumberFirstDigit = this.DiameterWholeNumberFirstDigit;
            tblProductStock.DiameterWholeNumberSecondDigit = this.DiameterWholeNumberSecondDigit;
            tblProductStock.DiameterFractionNumberFirstDigit = this.DiameterFractionNumberFirstDigit;
            tblProductStock.DiameterFractionNumberSecondDigit = this.DiameterFractionNumberSecondDigit;
            tblProductStock.DiameterValue = Convert.ToDecimal(this.DiameterValue);
            tblProductStock.DiameterUnit = this.DiameterUnit;
            tblProductStock.ThreadCountWholeNumberFirstDigit = this.ThreadCountWholeNumberFirstDigit;
            tblProductStock.ThreadCountWholeNumberSecondDigit = this.ThreadCountWholeNumberSecondDigit;
            tblProductStock.ThreadCountFractionNumberFirstDigit = this.ThreadCountFractionNumberFirstDigit;
            tblProductStock.ThreadCountFractionNumberSecondDigit = this.ThreadCountFractionNumberSecondDigit;
            tblProductStock.ThreadCountValue = Convert.ToDecimal(this.ThreadCountValue);
            tblProductStock.ThreadCountUnit = this.ThreadCountUnit;
            tblProductStock.LengthWholeNumberFirstDigit = this.LengthWholeNumberFirstDigit;
            tblProductStock.LengthWholeNumberSecondDigit = this.LengthWholeNumberSecondDigit;
            tblProductStock.LengthFractionNumberFirstDigit = this.LengthFractionNumberFirstDigit;
            tblProductStock.LengthFractionNumberSecondDigit = this.LengthFractionNumberSecondDigit;
            tblProductStock.LengthValue = Convert.ToDecimal(this.LengthValue);
            tblProductStock.LengthUnit = this.LengthUnit;
            tblProductStock.StockAmount = this.StockAmount;
            tblProductStock.ProductId = this.ProductId;
            tblProductStock.PkgQuanity = this.PkgQuanity;
            tblProductStock.UseDecimalForSize = this.UseDecimalForSize;
            tblProductStock.Save();
        }

        public static ReadWriteCustomCollection<ProductStock> GetStockByProductId(int productId)
        {
            return LoadFromCustomCollection(TblProductStockExtended.GetProductStockByProductId(productId));
        }
    }
}
